// pages/my/myIndex/myIndex.js
const app = getApp();
var util=require("../../../utils/util")
Page({
  /**
   * 页面的初始数据
   */
  data: {
    windowHeight: "", //屏幕高度px
    listBoxpaddbottom: "", //底部填充高度
    toppadding: "", //顶部填充
    authorShow: false, //显示授权弹框
    wxImg: "", //微信头像
    wxName: "欢迎使用联唱k歌", //微信昵称
    playNumber:"0",
    playedNumber:"0",
    favoriteNumber:"0",
  },
  // 帮助中心、意见反馈、、、、、
  gotoList(e) {
    console.log(e.currentTarget.dataset.type);
    switch (e.currentTarget.dataset.type) {
      case "helpCenter":
        wx.navigateTo({
          url: "../helpCenter/helpCenter",
        });
        break;
      case "feedbackList":
        wx.navigateTo({
          url: "../feedbackList/feedbackList",
        });
        break;
      case "songFeedback":
        wx.navigateTo({
          url: "../songFeedback/songFeedback",
        });
        break;
      case "chat":
        wx.navigateTo({
          url: "../chat/chat",
        });
        break;
    }
  },
  // 已点、演唱、收藏列表
  gotoyidian(e) {
    wx.navigateTo({
      url: "../../alreadyList/alreadyList?index=" + e.currentTarget.dataset.index,
    });
  },
  // 显示授权弹框
  openAuthor() {
    if (this.data.wxImg || this.data.wxName) {
      console.log("有信息");
    } else {
      this.setData({
        authorShow: true,
      });
    }
  },
  // 关闭授权弹框
  closeAuthor() {
    this.setData({
      authorShow: false,
    });
  },
  // 微信授权
  getUserInfo(res) {
    console.log(res.detail.userInfo.avatarUrl, "微信头像");
    console.log(res.detail.userInfo.nickName, "微信昵称");
    wx.setStorageSync("wxImg", res.detail.userInfo.avatarUrl);
    wx.setStorageSync("wxName", res.detail.userInfo.nickName);
    this.setData({
      wxImg: res.detail.userInfo.avatarUrl,
      wxName: res.detail.userInfo.nickName,
      authorShow: false,
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    console.log(wx.getSystemInfoSync().windowHeight);

    if (wx.getSystemInfoSync().windowHeight >= 640) {
      this.setData({
        windowHeight: wx.getSystemInfoSync().windowHeight,
        listBoxpaddbottom: Number(wx.getSystemInfoSync().windowHeight) * 0.303,
        toppadding: Number(wx.getSystemInfoSync().windowHeight) * 0.1,
      });
    } else {
      this.setData({
        windowHeight: wx.getSystemInfoSync().windowHeight,
        listBoxpaddbottom: Number(wx.getSystemInfoSync().windowHeight) * 0.249,
        toppadding: Number(wx.getSystemInfoSync().windowHeight) * 0.049,
      });
    }
  },

  /**
   * 打开客服聊天回调
   */
  chat(e) {
    console.log(e, "客服");
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    that.setData({
      token: wx.getStorageSync("token"),
      wxImg: wx.getStorageSync("wxImg"),
      wxName: wx.getStorageSync("wxName"),
    });
    console.log(util.postToken, "方法");
    util.postToken("/wechat/playlist", {}, that.data.token, function (res) {
      console.log("已点列表", res.data.total);
      let playNumber = res.data.total;
      that.setData({
        playNumber
      })
    });
    util.postToken("/wechat/playedlist", {}, that.data.token, function (res) {
      console.log("已唱列表", res.data.total);
      let playedNumber = res.data.total;
      that.setData({
        playedNumber
      })
    });
    util.postToken("/wechat/songs/favorites/list", {}, that.data.token, function (
      res
    ) {
      console.log("收藏列表", res.data.total);
      let favoriteNumber = res.data.total;
      that.setData({
        favoriteNumber
      })
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
});
